import type {
  cancelPrepaymentType,
  collectType,
  createOrderType,
  getFoodMsgType,
  getPackageDetailsType,
  getSearchDeviceType,
  postGoToResultType,
} from '@/types/eat'
import { http } from '@/utils/http'

/**
 * * postCollectApi 收藏接口 POST 	/device/applet/favorites
 * @param clientId 用户本地缓存的id
 * @param machineId 设备的id
 */
export const postCollectApi = (data: { clientId: string; machineId: string }) => {
  return http<any>({
    method: 'POST',
    url: '/client/favorites',
    data,
  })
}
/**
 * * getFoodMsgApi  获取餐品信息 GET  /device/applet/combo/limit
 */

export const getFoodMsgApi = (data: getFoodMsgType) => {
  const cityName = JSON.parse(uni.getStorageSync('location'))?.location?.cityName || '杭州市'
  return http<any>({
    method: 'GET',
    url: '/client/machine/combolist',
    data: { ...data, cityName },
  })
}
/**
 *
 * * getUpdateCartApi 更新购物车数据接口
 * @returns
 */
export const getUpdateCartApi = (data: { machineId: string }) => {
  return http<any>({
    method: 'GET',
    url: '/order/applet/shopping_cart',
    data,
  })
}
/**
 * * getSearchDeviceApi 模糊搜索 GET /device/applet/coordinate/search/limit/name
 */
export const getSearchDeviceApi = (data: getSearchDeviceType) => {
  return http<any>({
    method: 'GET',
    url: '/order/device/applet/coordinate/search/limit/name',
    data,
  })
}
/**
 * * getPackageDetailsApi 套餐详情 GET /device/applet/combo/detail
 */
export const getPackageDetailsApi = (data: getPackageDetailsType) => {
  return http<any>({
    method: 'GET',
    url: '/order/device/applet/combo/detail',
    data,
  })
}
/**
 * * postGoToResultApi 去结算  POST /applet/shopping_cart
 */

export const postGoToResultApi = (data: postGoToResultType) => {
  return http<any>({
    method: 'POST',
    url: '/order/applet/shopping_cart',
    data,
  })
}

/**
 * * 订单结算-获取优惠券信息-接口  /client/order/settlement/info
 */
export const postOrderSettlementApi = (data: createOrderType) => {
  return http<any>({
    method: 'POST',
    url: '/client/order/settlement/info',
    data,
  })
}
/**
 * * postPrepaymentOrderApi 预订单接口
 *
 */
export const postCreateOrderApi = (data: createOrderType) => {
  return http<any>({
    method: 'POST',
    url: '/client/order/create',
    data,
  })
}
/**
 *
 * * postCancelPrepaymentApi 取消预支付订单
 *
 */
export const postCancelPrepaymentApi = (data: cancelPrepaymentType) => {
  return http<any>({
    method: 'POST',
    url: '/order/applet/cancel',
    data,
  })
}

/**
 * * 获取排队数量
 * @param machineId string 设备ID
 * @returns
 */
export const getAwaitNumApi = (data: { machineId: string }) => {
  return http<any>({
    method: 'GET',
    url: '/client/order/awaitNum',
    data,
  })
}

/**
 * * 邀请有礼-排行榜
 * @param marketingId string 营销 ID
 * @returns
 */
export const getRankingsListApi = (data: { marketingId: string }) => {
  return http<any>({
    method: 'GET',
    url: '/client/clientActivity/rewards/rank',
    data,
  })
}

/**
 * * 礼包虚拟商品列表
 */
export const getCouponPackListApi = () => {
  const cityName = JSON.parse(uni.getStorageSync('location'))?.location?.cityName || '杭州市'
  return http<any>({
    method: 'GET',
    url: '/client/machine/couponPack-list',
    data: { cityName },
  })
}
/**
 * * 套餐结算-去支付
 */
export const creatCouponPackOrderApi = (data: any) => {
  return http<any>({
    method: 'POST',
    url: '/client/couponPack-order/settle',
    data,
  })
}
/**
 * * 取消礼包订单
 */
export const cancelCouponPackOrderApi = (data: any) => {
  return http<any>({
    method: 'GET',
    url: '/client/couponPack-order/cancel',
    data,
  })
}
/**
 * * 校验礼包支付
 */
export const checkCouponPackOrderApi = (data: any) => {
  return http<any>({
    method: 'GET',
    url: '/client/couponPack-order/settle/check',
    data,
  })
}
